home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / snip9503 / strdel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-14  |  1.1 KB  |  51 lines

  1. /*
  2. **  STRDEL.C - Removes specified characters from a string
  3. **
  4. **  public domain demo by Bob Stout
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. char *strdel(char *string, size_t first, size_t len)
  11. {
  12.       char *pos0, *pos1;
  13.  
  14.       if (string)
  15.       {
  16.             if (first < strlen(string))
  17.             {
  18.                   for (pos0 = pos1 = string + first;
  19.                         *pos1 && len;
  20.                         ++pos1, --len)
  21.                   {
  22.                         ;
  23.                   }
  24.                   strcpy(pos0, pos1);
  25.             }
  26.       }
  27.       return string;
  28. }
  29.  
  30. #ifdef TEST
  31.  
  32. main(int argc, char *argv[])
  33. {
  34.       int pos, len;
  35.  
  36.       if (4 > argc)
  37.       {
  38.             puts("Usage: STRDEL string pos len");
  39.             puts("Deletes 'len' characters starting at position 'pos'");
  40.             return -1;
  41.       }
  42.       pos = atoi(argv[2]);
  43.       len = atoi(argv[3]);
  44.       printf("strdel(\"%s\", %d, %d) => ", argv[1], pos, len);
  45.       printf("\"%s\"\n", strdel(argv[1], pos, len));
  46.       return 0;
  47. }
  48.  
  49. #endif /* TEST */
  50.  
  51.